"""
绘图脚本
- 调用 utils/plot_style.py 的字体与风格设置函数
"""

import matplotlib.pyplot as plt
from utils.plot_style import setup_chinese_font, set_plot_style
from src.core_utils import ensure_dir, save_figure, show_all_images
import os
import yaml
from PIL import Image

# 读取 config.yaml 参数
with open("config.yaml", "r", encoding="utf-8") as f:
    config = yaml.safe_load(f)

if __name__ == "__main__":
    # 设置中文字体和绘图风格
    setup_chinese_font()
    style_cfg = {
        'style': 'darkgrid',
        'dpi': 300,
        'figsize': [4, 3],  # 更小的图片尺寸
        'bbox_inches': 'tight'
    }
    set_plot_style(style_cfg)

    # 强制全局中文字体为 Heiti TC，防止中文乱码
    plt.rcParams['font.sans-serif'] = ['Heiti TC']
    plt.rcParams['axes.unicode_minus'] = False

    # 示例数据
    x = [1, 2, 3, 4]
    y = [10, 20, 15, 25]

    plt.figure()
    plt.plot(x, y, marker='o')
    fontdict_title = {'family': config['plot']['font_family'], 'fontsize': 10}
    fontdict_label = {'family': config['plot']['font_family'], 'fontsize': 8}
    plt.title("中文标题示例", fontdict=fontdict_title)
    plt.xlabel("横轴：变量X", fontdict=fontdict_label)
    plt.ylabel("纵轴：变量Y", fontdict=fontdict_label)
    plt.grid(True)
    plt.tight_layout()
    img_filename = "plot_demo.png"
    img_path = save_figure(plt, img_filename)
